﻿

	function expandAllQuestions()
	{
//			boolean expand = false;
//			if ($('#expandAllQuestions').is(':checked')){
//				$('#expandAllQuestions').val('collapse all');
//			} else {
//				expand = true;
//				$("#txtAge").hide();
//			} 
	}
		
		
    function getPixelLength(score)
    {
      var result = 0;
      result = score/4.00;
      result = 400*result;
      return result;
    }
		
    function getPixelLengthBasic()
    {
      var result = [];
      result.push(getAnswerLength(window.currentSD));
      result.push(getAnswerLength(window.currentD));
      result.push(getAnswerLength(window.currentN));
      result.push(getAnswerLength(window.currentA));
      result.push(getAnswerLength(window.currentSA));
      return result;		
    }
		
    function getAnswerLength(answerCount)
    {
      if(answerCount == 0 || window.currentTotal == 0)
      {
        return 0;
      }
      var returnValue = ((answerCount/window.currentTotal) * window.totalBarLength);
      return returnValue;
    }
		
	function essayQuery(crn, semester, year){
			
		jQuery.get('https://chitester1dev.weber.edu:6838/misc/weber/CSEvals/essayAnswers.cfm?crn='+crn+'&semester='+semester+'&year='+year+'&testId='+TestID, function(data) {
		
			var numberOfStudents = 0;
			var questionsAndResponses = [];
			var questionIndex = 0;
			
			// Get number of students and create the array
			$.each(data.DATA, function(i,array) {
			
				var tempArray = [];
								
				var questionFound = false;
			
				for(var questionData = 0; questionData < questionsAndResponses.length; questionData++){
				
					if(array[5] == questionsAndResponses[questionData][0]){
					
						questionFound = true;
						break;
					
					}
				
				}
				
				if(questionFound == false){
			
					tempArray[0] = array[5];

					questionsAndResponses[questionIndex] = tempArray;
					questionIndex++;
				}
			
				if(numberOfStudents < parseInt(array[7])){
				
					numberOfStudents = parseInt(array[7]);
				
				}
			
			});
					
			for(var studentNum = 0; studentNum < numberOfStudents; studentNum++){
				
				for(var q = 0; q < questionsAndResponses.length; q++){
				
					var studentResponseFound = false;					
				
					$.each(data.DATA, function(i,array) {
					
						if(questionsAndResponses[q][0] == array[5] && studentNum == array[7]){
																					
								questionsAndResponses[q].push(array[6]);
								studentResponseFound = true;
								return false;
																				
						}
					
					});
					
					if(!studentResponseFound){
						questionsAndResponses[q].push("No Response");
					}
				}
			}
			
			var eQuestions = "";
			
			for(var printQuestion = 0; printQuestion < questionsAndResponses.length; printQuestion++){
			
				var tempArray = questionsAndResponses[printQuestion];
				eQuestions += "<div class='question_box'><table class='essay_table_settings'><tr><td style='vertical-align:text-top; text-align:right'>"+ (printQuestion + 1) + ".</td><td></td><td align='left'>" + tempArray[0] + "</td></tr>";
				for(var responses = 1; responses < tempArray.length; responses++){
				
					var noResponse = "";
					
					if(tempArray[responses] == "No Response"){
						
						noResponse = "font-style:italic";
						
					}
					eQuestions += "<tr><td style='font-weight:normal; vertical-align:text-bottom; text-align:right'>&nbsp;&nbsp;" + responses + "</td><td align='right'></td><td align='left' class='essay_responses' style='" + noResponse + "'><pre>" + tempArray[responses] + "</pre></td></tr>";
				}
				eQuestions += "</table></div>";
			}
			$("#EssayWrapper").append(eQuestions);
		});
	}
		
    function mainQuery(crn, semester, year)
    {
		$.ajax({
		url: 'https://chitester1dev.weber.edu:6838/misc/weber/CSEvals/AnswerCount.cfm?crn='+crn+'&semester='+semester+'&year='+year+'&testId='+TestID,
		type: "GET",
		dataType:"json",
		success: function(data)
		{
			$.each(data.DATA, function(i,array)
			{
				window.currentQuestion = array[2];
				window.currentQuestionID = array[5];
				window.currentQuestionSequence = array[6];
				$.each(data.DATA, function(i,innerArray) {
					if(window.currentQuestion == innerArray[2] && window.finishedQuestions.indexOf(window.currentQuestion + " - " + innerArray[3]) == -1)
					{
						switch(innerArray[3])
						{
							case 'strongly disagree' :
							case 'very poor' :
								window.currentSD+= +innerArray[4];
								window.currentTotal+= +innerArray[4];
								break;
							case 'disagree' :
							case 'poor' :
								window.currentD+= +innerArray[4];
								window.currentTotal+= +innerArray[4];						  
								break;
							case 'neutral' :
							case 'average' :
								window.currentN+= +innerArray[4];
								window.currentTotal+= +innerArray[4];
								break;
							case 'agree' :
							case 'good' :
								window.currentA+= +innerArray[4];
								window.currentTotal+= +innerArray[4];
								break;					
							case 'strongly agree' :
							case 'excellent' :
								window.currentSA+= +innerArray[4];
								window.currentTotal+= +innerArray[4];
								break;
						}
						window.finishedQuestions.push(window.currentQuestion + " - " + innerArray[3]);
					}
				});
			
				if(window.printedQuestions.indexOf(window.currentQuestion) == -1)
				{
					questionCollapserId++;
					totalQuestions++;
					window.currentLengths = getPixelLengthBasic();
					window.printedQuestions.push(window.currentQuestion);
					$("#array").append('<p style="clear:both;">' + window.currentQuestion + " - " + window.currentSD + " - " + window.currentD + " - "  + window.currentN + " - " + window.currentA +" - " + window.currentSA +" - " + window.currentTotal + "</p>" );
					
					var buildString = '<div class="question_box question_box_collapsed '+questionCollapserId+'"><button id="' + questionCollapserId + '" class="button">↕</button><input type="hidden" class="hiddenQuestionID" value="'+window.currentQuestionID+'"/><div class="toggle">';
					buildString += '<div class="question">'+window.currentQuestionSequence + ".) " + window.currentQuestion+'</div><div class="question_graph">';
					buildString += '<div class="graph_box graphStronglyDisagree" style=" width:'+window.currentLengths[0]+'px;">';
					buildString += '</div><div class="graph_box graphDisagree" style=" width:'+window.currentLengths[1]+'px;">';
					buildString += '</div><div class="graph_box graphNeutral" style=" width:'+window.currentLengths[2]+'px;">';
					buildString += '</div><div class="graph_box graphAgree" style=" width:'+window.currentLengths[3]+'px;">';
					buildString += '</div><div class="graph_box graphStronglyAgree" style=" width:'+window.currentLengths[4]+'px;">';
					buildString += '</div></div><table class="question_scores"><tr><td class="question_answers_collapsed">SD: '+window.currentSD+'</td>';
					buildString += '<td class="question_answers_collapsed">D: '+window.currentD+'</td>';
					buildString += '<td class="question_answers_collapsed">N: '+window.currentN+'</td>';
					buildString += '<td class="question_answers_collapsed">A: '+window.currentA+'</td>';
					buildString += '<td class="question_answers_collapsed">SA: '+window.currentSA+'</td>';
					buildString += '</tr></table><br/></div></div>';	
					buildString += '<div class="question_box question_box_expanded '+questionCollapserId+'"></div>';
					var q = {};
					q[0] = window.currentQuestion;
					q[1] = window.currentSD;
					q[2] = window.currentD;
					q[3] = window.currentN;
					q[4] = window.currentA;
					q[5] = window.currentSA;
					q[6] = window.currentTotal;
					questionJSON[questionCollapserId] = q;
					$("#questions_wrapper").append(buildString);
				}
			
				window.currentQuestion = " ";
				window.currentSD = 0;
				window.currentD = 0;
				window.currentN = 0;
				window.currentA = 0;
				window.currentSA = 0;
				window.currentTotal = 0;
			});
		}
		});
	}
	

	
	function titleQuery(crn,semester,year)
	{
		$.ajax({
			url: 'https://chitester1dev.weber.edu:6838/misc/weber/CSEvals/CrnDetails.cfm?crn='+crn+'&semester='+semester+'&year='+year+'&testId='+TestID,
			type: "GET",
			dataType: "json",
			success: function (data) 
			{
				$.each(data.DATA, function(i,array) 
				{
					window.ClassName = array[0];
					$("#title_wrapper").append('<h2>Course Evaluation</h2>'+array[10]+' '+array[11]+' - '+array[0]+' '+array[1]+' '+array[4]+' '+array[6]+'');
				});
			}
		});
	}
   
 function topQuery(crn,semester,year)
    {
		$("#StatisticsWrapper").hide();
		jQuery.get('https://chitester1dev.weber.edu:6838/misc/weber/CSEvals/CrnStatistics.cfm?crn='+crn+'&semester='+semester+'&year='+year+'&testId='+TestID, function(data) 
		{
			var statsTableString = '';
			$.each(data.DATA, function(i,array) 
			{
				
				crnStatistics = array.slice(0);
				var tempString = '';
				tempString = tempString + '<table id="topTable">';
				tempString = tempString + '		<tbody><tr>';
				tempString = tempString + '			<td></td>';
				tempString = tempString + '			<td></td>';
				tempString = tempString + '			<td></td>';
				tempString = tempString + '			<td style="max-width:100px;text-align:center;font-size:12px;">Standard Deviation</td>';
				tempString = tempString + '		</tr>';
				tempString = tempString + '		<tr>';
				tempString = tempString + '			<!--<td style="width: 40px"><div class="expander"><div class="minus">-</div></div></td>-->';
				tempString = tempString + '			<td class="bigger bolder" style="width: 300px;">Your Overall Score</td>';
				tempString = tempString + '			<td class="bigger bolder" style="width: 60px">'+Number(array[4]).toFixed(2)+'</td>';
				tempString = tempString + '			<td><div class="container ticks"><div class="overall_ bigbar yellow ticks" style="width:'+getPixelLength(array[4]).toFixed(2)+'px"></div></div></td>';
				tempString = tempString + '			<td style="width: 100px; text-align:center">'+Number(array[5]).toFixed(2)+'</td>';
				tempString = tempString + '		</tr>';
				tempString = tempString + '	</tbody>';
				tempString = tempString + ' </table>';
				$("#StatisticsWrapper").prepend(tempString);
				$("#StatisticsWrapper").slideDown(200);
				jQuery.get('https://chitester1dev.weber.edu:6838/misc/weber/CSEvals/ScoreByCategory.cfm?crn='+crn+'&semester='+semester+'&year='+year+'&testId='+TestID, function(data2) 
				{
					statsTableString = statsTableString + ''
					$.each(data2.DATA, function(i,array2) 
					{
						var questionNumList = array2[4].split(',');
						var orderingPrintString = "";
						for(var i = 0; i < questionNumList.length; i++){
						
							questionNumList[i] = parseInt(questionNumList[i]);
						
						}

						questionNumList.sort(function(a,b){return a-b});
						
						for(var i = 0; i < questionNumList.length; i++){
						
							orderingPrintString += questionNumList[i];
							if(i != questionNumList.length - 1){
								orderingPrintString += ", ";
							}
						}
						
						statsTableString = statsTableString + '<tr style="display:none;">';
						statsTableString = statsTableString + '	<td style="width: 300px;">'+array2[2]+' (Qs '+orderingPrintString+')</td>';
						statsTableString = statsTableString + '	<td style="width: 60px">'+Number(array2[0]).toFixed(2)+'</td>';
						statsTableString = statsTableString + '	<td><div class="container"><div class="overall_bar yellow" style="width:'+getPixelLength(array2[0]).toFixed(2)+'px"></div></div></td>';
						statsTableString = statsTableString + '	<td style="width: 100px; text-align:center">'+Number(array2[1]).toFixed(2)+'</td>';
						statsTableString = statsTableString + '</tr>';
					});
				}).done(function() { 
					statsTableString = statsTableString + '<tr class="gap" style="display:none;">';
					statsTableString = statsTableString + '	<td style="width: 300px;">Your Overall Semester Average</td>';
					statsTableString = statsTableString + '	<td style="width: 60px">'+Number(window.crnStatistics[0]).toFixed(2)+'</td>';
					statsTableString = statsTableString + '	<td><div class="container"><div class="overall_bar " style="width:'+getPixelLength(window.crnStatistics[0]).toFixed(2)+'px"></div></div></td>';
					statsTableString = statsTableString + '	<td style="width: 100px;text-align:center">'+Number(window.crnStatistics[1]).toFixed(2)+'</td>';
					statsTableString = statsTableString + '</tr>';
					statsTableString = statsTableString + '<tr style="display:none;">';
					statsTableString = statsTableString + '	<td style="width: 300px;">Dept. Semester Average</td>';
					statsTableString = statsTableString + '	<td style="width: 60px">'+Number(window.crnStatistics[2]).toFixed(2)+'</td>';
					statsTableString = statsTableString + '	<td><div class="container"><div class="overall_bar" style="width:'+getPixelLength(window.crnStatistics[2]).toFixed(2)+'px"></div></div></td>';
					statsTableString = statsTableString + '	<td style="width: 100px;text-align:center">'+Number(window.crnStatistics[3]).toFixed(2)+'</td>';
					statsTableString = statsTableString + '</tr>';
					statsTableString = statsTableString + '<tr style="display:none;">';
					statsTableString = statsTableString + '	<td style="width: 300px;">Dept. '+window.ClassName+' 5 Year Average</td>';
					statsTableString = statsTableString + '	<td style="width: 60px">'+Number(window.crnStatistics[7]).toFixed(2)+'</td>';
					statsTableString = statsTableString + '	<td><div class="container"><div class="overall_bar" style="width:'+getPixelLength(window.crnStatistics[7]).toFixed(2)+'px"></div></div></td>';
					statsTableString = statsTableString + '	<td style="width: 100px;text-align:center">'+Number(window.crnStatistics[8]).toFixed(2)+'</td>';
					statsTableString = statsTableString + '</tr>';
					statsTableString = statsTableString + '<tr style="display:none;">';
					statsTableString = statsTableString + '	<td style="width: 300px;">Your '+window.ClassName+' 5 Year Average</td>';
					statsTableString = statsTableString + '	<td style="width: 60px">'+Number(window.crnStatistics[9]).toFixed(2)+'</td>';
					statsTableString = statsTableString + '	<td><div class="container"><div class="overall_bar" style="width:'+getPixelLength(window.crnStatistics[9]).toFixed(2)+'px"></div></div></td>';
					statsTableString = statsTableString + '	<td style="width: 100px;text-align:center">'+Number(window.crnStatistics[10]).toFixed(2)+'</td>';
					statsTableString = statsTableString + '</tr>';
					statsTableString = statsTableString + '<tr style="display:none;">';
					statsTableString = statsTableString + '	<td class="bolder" style="text-align:center;" colspan="4">A score of '+Number(window.crnStatistics[4]).toFixed(2)+' places you in the '+Number(window.crnStatistics[6]).toFixed(2)+'th percentile of your department this semester.</td>';
					statsTableString = statsTableString + '</tr>';
					statsTableString = statsTableString + '';
					
					$("#topTable").append(statsTableString);
					$("#topTable").find(":hidden").slideDown(500);
					$(".loadinggif").remove();
				});
			});
		});
    }	

	function detailsQuery(crn, semester, year, questionId, clickedButton)
    {
		var UIspeed = 100;
		//$(clickedButton).attr("id")
		var questionNumber = $(clickedButton).attr("id");
		var originalDiv = $(clickedButton).parent();	
		if($(originalDiv).hasClass('question_box_expanded'))
		{
			originalDiv.slideUp(UIspeed);
			var collapseDiv = $(originalDiv).siblings(".question_box_collapsed").filter('.' + questionNumber);
			collapseDiv.slideDown(UIspeed);
			return;
		}

		var expanderDiv = $(clickedButton).parent().siblings(".question_box_expanded").filter('.' + questionNumber);
		
		if($(originalDiv).hasClass("Already_Expanded"))
		{
			expanderDiv.slideDown(UIspeed);
			originalDiv.slideUp(UIspeed);
			return;
		}
		$.ajax({
			url:("https://chitester1dev.weber.edu:6838/misc/weber/CSEvals/QuestionDetails.cfm?crn="+crn+"&semester="+semester+"&year="+year+"&questionID="+questionId),
			type:"GET",
			dataType:"json",
			success: function (data) {
				var connectionString = '';
					$.each(data.DATA, function(i,array)
					{
						resultString +='			<button id="' + questionNumber + '" class="button '+questionNumber+'">↕</button>';
						resultString +='<table class="table_settings" border="0" style="position:relative; left:55px; margin-top:0px; margin-bottom:-5px; width:900px;">			';
						resultString +='					<tbody><tr>	';
						resultString +='						<td colspan="7">';
						resultString +='							<div class="question hiddenQuestion">';
						resultString +='									'+questionNumber + '.) '+ questionJSON[questionNumber][0];+'';
						resultString +='							</div>';
						resultString +='						</td>';
						resultString +='					</tr>';
						resultString +='					<tr>';
						resultString +='						<td align="left" style="width:225px"> </td>';
						resultString +='						<td align="left" >SD</td>	';
						resultString +='						<td align="left" >D</td>';
						resultString +='						<td align="left" >N</td>';
						resultString +='						<td align="left" >A</td>';
						resultString +='						<td align="left" >SA</td>	';
						resultString +='						<td align="left"></td>';
						resultString +='					</tr>';
						resultString +='					<tr>';
						resultString +='						<td align="left" style="width:225px"> </td>';
						resultString +='						<td align="left" style="width:47">'+questionJSON[questionNumber][1]+'</td>	';
						resultString +='						<td align="left" style="width:47">'+questionJSON[questionNumber][2]+'</td>';
						resultString +='						<td align="left" style="width:47">'+questionJSON[questionNumber][3]+'</td>';
						resultString +='						<td align="left" style="width:47">'+questionJSON[questionNumber][4]+'</td>';
						resultString +='						<td align="left" style="width:47">'+questionJSON[questionNumber][5]+'</td>	';
						resultString +='						<td align="left" rowspan="2"> ';
						resultString +='						<div class="graph_expanded">';
						resultString +='								<div class="graph_box graphStronglyDisagree" style="width:'+((questionJSON[questionNumber][1])/(questionJSON[questionNumber][6]))*400+'px"></div>	';
						resultString +='								<div class="graph_box graphDisagree" style="width:'+((questionJSON[questionNumber][2])/(questionJSON[questionNumber][6]))*400+'px"></div>';
						resultString +='								<div class="graph_box graphNeutral" style="width:'+((questionJSON[questionNumber][3])/(questionJSON[questionNumber][6]))*400+'px"></div>';
						resultString +='								<div class="graph_box graphAgree" style="width:'+((questionJSON[questionNumber][4])/(questionJSON[questionNumber][6]))*400+'px"></div>';
						resultString +='								<div class="graph_box graphStronglyAgree" style="width:'+((questionJSON[questionNumber][5])/(questionJSON[questionNumber][6]))*400+'px"></div>				';
						resultString +='						</div>';
						resultString +='						</td>';
						resultString +='					</tr>';
						resultString +='					<tr>';
						resultString +='						<td align="left" style="width:225px"> </td>';
						resultString +='						<td align="left" style="width:47">'+((questionJSON[questionNumber][1]/questionJSON[questionNumber][6])*100).toFixed(0)+'%</td>	';
						resultString +='						<td align="left" style="width:47">'+((questionJSON[questionNumber][2]/questionJSON[questionNumber][6])*100).toFixed(0)+'%</td>';
						resultString +='						<td align="left" style="width:47">'+((questionJSON[questionNumber][3]/questionJSON[questionNumber][6])*100).toFixed(0)+'%</td>';
						resultString +='						<td align="left" style="width:47">'+((questionJSON[questionNumber][4]/questionJSON[questionNumber][6])*100).toFixed(0)+'%</td>';
						resultString +='						<td align="left" style="width:47">'+((questionJSON[questionNumber][5]/questionJSON[questionNumber][6])*100).toFixed(0)+'%</td>	';
						resultString +='					</tr>	';
						resultString +='					<tr>';
						resultString +='						<td align="left" style="width:100px">Dpt Average This Semester</td>';
						resultString +='						<td align="left" style="width:47">'+((array[33]/array[34])*100).toFixed(0)+'%</td>	';
						resultString +='						<td align="left" style="width:47">'+((array[32]/array[34])*100).toFixed(0)+'%</td>';
						resultString +='						<td align="left" style="width:47">'+((array[31]/array[34])*100).toFixed(0)+'%</td>';
						resultString +='						<td align="left" style="width:47">'+((array[30]/array[34])*100).toFixed(0)+'%</td>';
						resultString +='						<td align="left" style="width:47">'+((array[29]/array[34])*100).toFixed(0)+'%</td>	';
						resultString +='						<td align="left"> ';
						resultString +='						';
						resultString +='							<div class="graph_expanded">';
						resultString +='									<div class="graph_box_expanded graphStronglyDisagreeExpanded" style="width:'+((array[33]/array[34])*400)+'px;"></div>	';
						resultString +='									<div class="graph_box_expanded graphDisagreeExpanded" style="width:'+((array[32]/array[34])*400)+'px"></div>';
						resultString +='									<div class="graph_box_expanded graphNeutralExpanded" style="width:'+((array[31]/array[34])*400)+'px"></div>';
						resultString +='									<div class="graph_box_expanded graphAgreeExpanded" style="width:'+((array[30]/array[34])*400)+'px"></div>';
						resultString +='									<div class="graph_box_expanded graphStronglyAgreeExpanded" style="width:'+((array[29]/array[34])*400)+'px"></div>				';
						resultString +='							</div>';
						resultString +='						</td>';
						resultString +='					</tr>';
						resultString +='					';
						resultString +='					<tr>';
						resultString +='						<td align="left" style="width:100px">Your Overall Semester Average</td>';
						resultString +='						<td align="left" style="width:47">'+((array[18]/array[19])*100).toFixed(0)+'%</td>	';
						resultString +='						<td align="left" style="width:47">'+((array[17]/array[19])*100).toFixed(0)+'%</td>';
						resultString +='						<td align="left" style="width:47">'+((array[16]/array[19])*100).toFixed(0)+'%</td>';
						resultString +='						<td align="left" style="width:47">'+((array[15]/array[19])*100).toFixed(0)+'%</td>';
						resultString +='						<td align="left" style="width:47">'+((array[14]/array[19])*100).toFixed(0)+'%</td>	';
						resultString +='						<td align="left"> ';
						resultString +='						';
						resultString +='							<div class="graph_expanded">';
						resultString +='									<div class="graph_box_expanded graphStronglyDisagreeExpanded" style="width:'+((array[18]/array[19])*400)+'px;"></div>	';
						resultString +='									<div class="graph_box_expanded graphDisagreeExpanded" style="width:'+((array[17]/array[19])*400)+'px;"></div>';
						resultString +='									<div class="graph_box_expanded graphNeutralExpanded" style="width:'+((array[16]/array[19])*400)+'px;"></div>';
						resultString +='									<div class="graph_box_expanded graphAgreeExpanded" style="width:'+((array[15]/array[19])*400)+'px;"></div>';
						resultString +='									<div class="graph_box_expanded graphStronglyAgreeExpanded" style="width:'+((array[14]/array[19])*400)+'px;"></div>				';
						resultString +='							</div>';
						resultString +='						</td>';
						resultString +='					</tr>	';
						resultString +='					<tr>';
						resultString +='						<td align="left" style="width:100px">Dpt '+window.ClassName+' 5 Year Average</td>';
						resultString +='						<td align="left" style="width:47">'+((array[26]/array[27])*100).toFixed(0)+'%</td>	';
						resultString +='						<td align="left" style="width:47">'+((array[25]/array[27])*100).toFixed(0)+'%</td>';
						resultString +='						<td align="left" style="width:47">'+((array[24]/array[27])*100).toFixed(0)+'%</td>';
						resultString +='						<td align="left" style="width:47">'+((array[23]/array[27])*100).toFixed(0)+'%</td>';
						resultString +='						<td align="left" style="width:47">'+((array[22]/array[27])*100).toFixed(0)+'%</td>	';
						resultString +='						<td align="left"> ';
						resultString +='						';
						resultString +='							<div class="graph_expanded">';
						resultString +='									<div class="graph_box_expanded graphStronglyDisagreeExpanded" style="width:'+((array[26]/array[27])*400)+'px;"></div>	';
						resultString +='									<div class="graph_box_expanded graphDisagreeExpanded" style="width:'+((array[25]/array[27])*400)+'px;"></div>';
						resultString +='									<div class="graph_box_expanded graphNeutralExpanded" style="width:'+((array[24]/array[27])*400)+'px;"></div>';
						resultString +='									<div class="graph_box_expanded graphAgreeExpanded" style="width:'+((array[23]/array[27])*400)+'px;"></div>';
						resultString +='									<div class="graph_box_expanded graphStronglyAgreeExpanded" style="width:'+((array[22]/array[27])*400)+'px;"></div>				';
						resultString +='							</div>';
						resultString +='						';
						resultString +='						</td>';
						resultString +='					</tr>';
						resultString +='					<tr>';
						resultString +='						<td align="left" style="width:100px">Your '+window.ClassName+' 5 Year Average</td>';
						resultString +='						<td align="left" style="width:47">'+((array[7]/array[8])*100).toFixed(0)+'%</td>	';
						resultString +='						<td align="left" style="width:47">'+((array[6]/array[8])*100).toFixed(0)+'%</td>';
						resultString +='						<td align="left" style="width:47">'+((array[5]/array[8])*100).toFixed(0)+'%</td>';
						resultString +='						<td align="left" style="width:47">'+((array[4]/array[8])*100).toFixed(0)+'%</td>';
						resultString +='						<td align="left" style="width:47">'+((array[3]/array[8])*100).toFixed(0)+'%</td>	';
						resultString +='						<td align="left"> ';
						resultString +='							<div class="graph_expanded">';
						resultString +='									<div class="graph_box_expanded graphStronglyDisagreeExpanded" style="width:'+((array[7]/array[8])*400)+'px;"></div>	';
						resultString +='									<div class="graph_box_expanded graphDisagreeExpanded" style="width:'+((array[6]/array[8])*400)+'px;"></div>';
						resultString +='									<div class="graph_box_expanded graphNeutralExpanded" style="width:'+((array[5]/array[8])*400)+'px;"></div>';
						resultString +='									<div class="graph_box_expanded graphAgreeExpanded" style="width:'+((array[4]/array[8])*400)+'px;"></div>';
						resultString +='									<div class="graph_box_expanded graphStronglyAgreeExpanded" style="width:'+((array[3]/array[8])*400)+'px;"></div>				';
						resultString +='							</div>';
						resultString +='						</td>';
						resultString +='					</tr>	';
						resultString +='				</tbody></table>';
						resultString +='				</div>';
					});
					expanderDiv.hide();
					expanderDiv.append(resultString);
					
					originalDiv.slideUp(UIspeed);
					expanderDiv.slideDown(UIspeed);
					originalDiv.addClass("Already_Expanded");
					resultString = '';
			},
			error: function (xhr, ajaxOptions, thrownError, asdf) {
				alert("failed to process Ajax");
			}
		});
			
			

	}
	
	function printQuery(name, start, data)
	{
		var rs = "";
		var total = data.DATA[0][start+5];
		var sd = (data.DATA[0][start+4] / total) * 100;
		var d = (data.DATA[0][start+3] / total) * 100;
		var n = (data.DATA[0][start+2] / total) * 100;
		var a = (data.DATA[0][start+1] / total) * 100;
		var sa = (data.DATA[0][start] / total) * 100;
		var factor = 4;
		rs += "<tr class='result'>";
		rs += "<td>" + name + "</td>";
		rs += "<td> SD: " + Math.round(sd) + "% </td>";
		rs += "<td> D: " + Math.round(d) + "% </td>";
		rs += "<td> N: " + Math.round(n) + "% </td>";
		rs += "<td> A: " + Math.round(a) + "% </td>";
		rs += "<td> SA: " +Math.round(sa) + "% </td>";
		rs += '<td><div class="graph_box graphStronglyDisagree" style=" width:'+sd*factor+'px;"></div>';
		rs += '<div class="graph_box graphDisagree" style=" width:'+d*factor+'px;"></div>';
		rs += '<div class="graph_box graphNuteral" style=" width:'+n*factor+'px;"></div>';
		rs += '<div class="graph_box graphAgree" style=" width:'+a*factor+'px;"></div>';
		rs += '<div class="graph_box graphStronglyAgree" style=" width:'+sa*factor+'px;"></div>';
		rs += "</td></tr>";
		return rs;
	}
	
	
	
   $(function() {
		$(document).delegate(".button", "click", function(){ detailsQuery(CRN,Semester,Year,$(this).siblings(".hiddenQuestionID").val(), this);});

    });

	function getURLParameter(name) {
		return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
	}
	
	//Class_Breakdown_JRW_Preston.html?CRN=32981&Semester=3&Year=2013&TestID=64529
	var resultString = "";
	var QuestionID = 3979590;
    var CRN = 32981;
    var Semester = 3;
    var Year = 2013;
	var TestID = 64529;
    var totalBarLength = 400;
    var currentQuestion = " ";
    var currentSD = 0;
    var currentD = 0;
    var currentN = 0;
    var currentA = 0;
    var currentSA = 0;
    var currentTotal = 0;
    var currentLengths = [];
    var finishedQuestions = [];
    var printedQuestions = [];
	var crnStatistics = [];
	var questionCollapserId = 0;
	var totalQuestions = 0;
	var questionJSON = {};	
	CRN = parseInt(getURLParameter('CRN'));
	Semester = parseInt(getURLParameter('Semester'));
	Year = parseInt(getURLParameter('Year'));
	TestID = parseInt(getURLParameter('TestID'));
	window.onload=(function() {
		$("#StatisticsWrapper").before('<p class="loadinggif">Calculating...</p></br><img class="loadinggif" src=".\\images\\ajax-loader.gif" "/>');

		titleQuery(CRN, Semester, Year);
		mainQuery(CRN,Semester,Year);
		essayQuery(CRN, Semester, Year);		
		topQuery(CRN,Semester,Year);
			
    });
